<div>
  <!-- 面包屑导航 -->
  <el-breadcrumb separator-class="el-icon-arrow-right">
    <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
    <el-breadcrumb-item>用户管理</el-breadcrumb-item>
    <el-breadcrumb-item>用户列表</el-breadcrumb-item>
  </el-breadcrumb>
  <!-- 搜索框 -->
  <el-input
    placeholder="请输入内容"
    v-model="userInput"
    class="input-with-select"
    size="small"
  >
    <el-button slot="append" icon="el-icon-search" @click="search"></el-button>
  </el-input>
  <el-button slot="append" @click="dialogFormVisible = true"
    >添加用户</el-button
  >
  <!-- 主体 -->
  <el-table :data="usersData" style="width: 100%">
    <!-- 正常列--直接显示数字文本等，直接赋值 -->
    <el-table-column prop="username" label="姓名" width="180"></el-table-column>
    <el-table-column prop="email" label="邮箱" width="180"></el-table-column>
    <el-table-column prop="mobile" label="电话" width="180"></el-table-column>

    <!-- 自定义列--组件/需要处理数据后才能赋值 -->
    <el-table-column label="用户状态">
      <template slot-scope="scope">
        <el-switch
          v-model="scope.row.mg_state"
          active-color="#13ce66"
          inactive-color="#ff4949"
          @change="changeState(scope.row)"
        >
        </el-switch>
      </template>
    </el-table-column>
    <el-table-column label="操作">
      <template slot-scope="scope">
        <!-- 修改用户状态 -->
        <el-button
          :plain="true"
          size="mini"
          type="primary"
          icon="el-icon-edit"
          @click="editUsers(scope.row)"
        ></el-button>

        <!-- 删除用户模块 -->
        <el-button
          :plain="true"
          size="mini"
          type="warning"
          icon="el-icon-delete"
          @click="deleteUser(scope.row.id)"
        ></el-button>

        <!-- 分配角色模块 -->
        <el-button
          :plain="true"
          size="mini"
          type="success"
          icon="el-icon-check"
          @click="startAssignRights(scope.row)"
          >分配角色</el-button
        >
      </template>
    </el-table-column>
  </el-table>
  <!-- 分页 -->
  <el-pagination
    @current-change="clickpage"
    layout="prev, pager, next"
    :total="usersTotal"
    :page-size="pagesize"
    :current-page="currentPage"
  ></el-pagination>
  <!-- 添加用户模态框 -->
  <el-dialog title="添加用户" :visible.sync="dialogFormVisible">
    <el-form :model="form" ref="numberValidateForm">
      <!-- 用户名 -->
      <el-form-item
        label="用户名"
        prop="username"
        :label-width="formLabelWidth"
        :rules="[
      { required: true, message: '用户名不能为空',trigger:'blur'}
    ]"
      >
        <el-input v-model="form.username"></el-input>
      </el-form-item>
      <!-- 密码 -->
      <el-form-item
        label="密码"
        prop="password"
        :label-width="formLabelWidth"
        :rules="[
    { required: true, message: '密码不能为空',trigger:'blur'}
  ]"
      >
        <el-input v-model="form.password"></el-input>
      </el-form-item>
      <!-- 邮箱 -->
      <el-form-item
        label="邮箱"
        prop="email"
        :label-width="formLabelWidth"
        :rules="[
    { message: '邮箱格式不对',pattern:/^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/,trigger:'blur'}
  ]"
      >
        <el-input v-model="form.email"></el-input>
      </el-form-item>
      <!-- 手机 -->
      <el-form-item
        label="手机"
        prop="mobile"
        :label-width="formLabelWidth"
        :rules="[
    { message: '手机格式不对',pattern:/^[1](([3][0-9])|([4][5-9])|([5][0-3,5-9])|([6][5,6])|([7][0-8])|([8][0-9])|([9][1,8,9]))[0-9]{8}$/,trigger:'blur'}
  ]"
      >
        <el-input v-model="form.mobile"></el-input>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="resetForm('numberValidateForm')">重 置</el-button>
      <el-button type="primary" @click="submitForm('numberValidateForm')"
        >确 定</el-button
      >
    </div>
  </el-dialog>
  <!-- 修改用户模态框 -->
  <el-dialog title="收货地址" :visible.sync="editformVisible">
    <el-form :model="editForm" ref="editFormtag">
      <el-form-item
        label="姓名"
        :label-width="formLabelWidth"
        prop="username"
        :rules="[
      { required: true, message: '用户名不能为空',trigger:'blur'}
    ]"
      >
        <el-input v-model="editForm.username" autocomplete="off"></el-input>
      </el-form-item>
      <el-form-item
        label="邮箱"
        :label-width="formLabelWidth"
        prop="email"
        :rules="[
      { message: '邮箱格式不对',pattern:/^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/,trigger:'blur'}
    ]"
      >
        <el-input v-model="editForm.email" autocomplete="off"></el-input>
      </el-form-item>
      <el-form-item
        label="电话"
        :label-width="formLabelWidth"
        prop="mobile"
        :rules="[
      { message: '手机格式不对',pattern:/^[1](([3][0-9])|([4][5-9])|([5][0-3,5-9])|([6][5,6])|([7][0-8])|([8][0-9])|([9][1,8,9]))[0-9]{8}$/,trigger:'blur'}
    ]"
      >
        <el-input v-model="editForm.mobile" autocomplete="off"></el-input>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="editformVisible = false">取 消</el-button>
      <el-button type="primary" @click="editUsersConfirm('editFormtag')"
        >修 改</el-button
      >
    </div>
  </el-dialog>
  <!-- 分配角色模态框 -->
  <el-dialog title="分配角色" :visible.sync="rightsFormVisible" width="40%">
    <el-form :model="form">
      <el-form-item label="姓名" :label-width="formLabelWidth">
        <el-tag>{{ rightsForm.username }}</el-tag>
      </el-form-item>
      <el-form-item label="分配角色" :label-width="formLabelWidth">
        <el-select v-model="selectRoleID" placeholder="请选择角色">
          <el-option
            v-for="(item,index) in roleList"
            :key="item.id"
            :label="item.roleName"
            :value="item.id"
          ></el-option>
        </el-select>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="rightsFormVisible = false">取 消</el-button>
      <el-button type="primary" @click="confirmAssignRights">确 定</el-button>
    </div>
  </el-dialog>
</div>
